// pages/sendneedorder/sendneedorder.js
var app=getApp();
var c=require('../common.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showPayPwdInput:false,  //是否展示密码输入层
    pwdVal: '',  //输入的密码
    payFocus: true, //文本框焦点
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var order_id= options.order_id;
    var order_num = options.order_num;
    var paystatys = options.paystatys;
    if (paystatys){
      this.setData({ showPayPwdInput:true})
    }
    this.setData({ order_id: order_id, order_num: order_num});
    var that=this;
    var demand_id=options.id;

    that.setData({
      demand_id: demand_id,
    })
    c.ajax(
      app.url +'describeselect',
      { demand_id: demand_id},
      res=>{
        console.log(res);
        that.setData({ content: res.data.content, price: res.data.price, status: res.data.status})
      }
    )
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  wangsendmoney:function(){
    var status = this.data.status;
    if (status==0){
        wx.showToast({
          title: '余额不足',
          icon:'none'
        })
        return;
    }
  },
  /**
  * 显示支付密码输入层
  */
  showInputLayer: function () {
    var status = this.data.status;
    if (status==0){
     wx.showToast({
       title: '余额不足',
       icon:'none'
     })
     return;
    }
    this.setData({ showPayPwdInput: true, payFocus: true });
  },
  /**
   * 隐藏支付密码输入层
   */
  hidePayLayer: function () {
    var val = this.data.pwdVal;
    var order_id = this.data.order_id;
    var uid=app.u.user_id;
    var that=this;
    this.setData({ showPayPwdInput: false, payFocus: false, pwdVal: '' }, function () {
      var demand_id = that.data.demand_id;
      c.ajax(
          app.url+'orderpay',
        { uid: uid, val: val, order_id: order_id, demand_id: demand_id},
          res=>{
            if(res.data){
              wx.navigateTo({
                url: '/pages/sendneedsuccess/sendneedsuccess',
              })
            }else{
              wx.showToast({
                title: '支付密码错误',
                icon:'none'
              })
            }
          }
      )
    });

  },
  /**
   * 获取焦点
   */
  getFocus: function () {
    this.setData({ payFocus: true });
  },
  /**
   * 输入密码监听
   */
  inputPwd: function (e) {
    this.setData({ pwdVal: e.detail.value });

    if (e.detail.value.length >= 6) {
      this.hidePayLayer();
    }
  },
  passwordset:function(){
     wx.navigateTo({
       url: '/pages/sendneedsetpass/sendneedsetpass',
     })
  }
})